package face.pay.wxpay.controller;


import face.pay.util.ResultMessage;
import face.pay.wxpay.service.IWxJsPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/wxpay")
public class WxPayController {


    @Autowired
    private IWxJsPayService iWxJsPayService;


    /**
     * 查优惠券
     *
     * @return
     */
    @RequestMapping("/getCpnInfo")
    @ResponseBody
    public String getCpnInfo(String deviceId, String openId) {
        return this.iWxJsPayService.getCpnInfo(deviceId, openId);
    }


    /**
     * 发起支付
     *
     * @return
     */
    @RequestMapping("/jsPay")
    @ResponseBody
    public ResultMessage wxJsPay(String deviceId, String openId, String cpnId, String money, String act_money) {
        return this.iWxJsPayService.wxJsPay(deviceId, openId, cpnId, money, act_money);
    }


    /**
     * 支付结果回调
     *
     * @return
     */
    @RequestMapping(value = "/callback", produces = MediaType.APPLICATION_XML_VALUE)
    @ResponseBody
    public String WxpayCallback(@RequestBody String xmlData) {
        return this.iWxJsPayService.payCallback(xmlData);
    }
}
